package com.quasar.hpatient.module.home_inspection_chart;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.quasar.hpatient.R;
import com.quasar.hpatient.bean.home_assay_single.SingleItemBean;

import java.util.List;

import lib.quasar.base.frame.BaseActivity;
import lib.quasar.widget.chart.ChartView;

/**
 * description: 化验单, 单项分析
 * created by kalu on 2018/3/29 9:03
 */
public class HomeInspectionChartActivity extends BaseActivity<HomeInspectionChartPresenter> implements HomeInspectionChartView, View.OnClickListener {

    public final static String NAME = "NAME";
    public final static String UNIT = "UNIT";

    @Override
    public int initView() {
        return R.layout.activity_home_inspection_chart;
    }

    @Override
    public void initDataLocal() {

        final String name = getIntent().getStringExtra(NAME);
        final String unit = getIntent().getStringExtra(UNIT);
        Log.e("goSingle", "---name----" + name + "--unit---" + unit);
        TextView title = findViewById(R.id.activity_home_report_single_title);
        setText(title, name);
        findViewById(R.id.activity_home_report_back).setOnClickListener(this);
        getPresenter().initLayoutData(HomeInspectionChartActivity.this, unit);
    }

    @Override
    public void initDataNet() {

        HomeInspectionChartPresenter presenter = getPresenter();
        if (null == presenter) return;

        final String name = getIntent().getStringExtra(NAME);
        presenter.assaySingle(this, name);
    }

    @Override
    public void onClick(final View view) {
        switch (view.getId()) {
            case R.id.activity_home_report_back:
                onBackPressed();
                break;
        }
    }

    @Override
    public void setChart(List<SingleItemBean> entryList) {

        final ChartView chart = findViewById(R.id.activity_home_report_single_chart);
        if (null == chart) return;
        chart.notifyDataSetChanged(entryList);
    }

    @Override
    public void setChartNull() {

        final ChartView chart = findViewById(R.id.activity_home_report_single_chart);
        if (null == chart) return;
        chart.setHintText(getResources().getString(R.string.chart_null));
    }

    @Override
    public void setRecycler(boolean refresh, RecyclerView.Adapter adapter, RecyclerView.LayoutManager manager) {

        final RecyclerView recycler = findViewById(R.id.activity_home_report_single_recycle);
        if (null == recycler) return;

        if (refresh) {
            recycler.getAdapter().notifyDataSetChanged();
        } else {
            recycler.setLayoutManager(manager);
            recycler.setAdapter(adapter);
        }
    }
}